#pragma once


class CFile 
{

public:
// Flag values
	enum OpenFlags {
		modeRead =         (int) 0x00000,
		modeWrite =        (int) 0x00001,
		modeReadWrite =    (int) 0x00002,
		shareCompat =      (int) 0x00000,
		shareExclusive =   (int) 0x00010,
		shareDenyWrite =   (int) 0x00020,
		shareDenyRead =    (int) 0x00030,
		shareDenyNone =    (int) 0x00040,
		modeNoInherit =    (int) 0x00080,
		modeCreate =       (int) 0x01000,
		modeNoTruncate =   (int) 0x02000,
		typeText =         (int) 0x04000, // typeText and typeBinary are
		typeBinary =       (int) 0x08000, // used in derived classes only
		osNoBuffer =       (int) 0x10000,
		osWriteThrough =   (int) 0x20000,
		osRandomAccess =   (int) 0x40000,
		osSequentialScan = (int) 0x80000,
		};

	enum Attribute {
		normal =    0x00,
		readOnly =  0x01,
		hidden =    0x02,
		system =    0x04,
		volume =    0x08,
		directory = 0x10,
		archive =   0x20
		};

	enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };

	static const HANDLE hFileNull;

// Constructors
	CFile();
	CFile(HANDLE hFile);
	CFile(LPCTSTR lpszFileName, UINT nOpenFlags);

// Attributes
	HANDLE m_hFile;
	operator HANDLE() const;

	virtual ULONGLONG GetPosition() const;	
	/*
	virtual CString GetFileName() const;
	virtual CString GetFileTitle() const;
	virtual CString GetFilePath() const;
	virtual void SetFilePath(LPCTSTR lpszNewName);
	*/

// Operations
	virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags );

	static BOOL PASCAL Rename(LPCTSTR lpszOldName,
				LPCTSTR lpszNewName);
	static BOOL PASCAL Remove(LPCTSTR lpszFileName);

	ULONGLONG SeekToEnd();
	void SeekToBegin();

	ULONGLONG Seek(LONGLONG lOff, UINT nFrom);
	BOOL SetLength(ULONGLONG dwNewLen);
	ULONGLONG GetLength() const;

	UINT Read(void* lpBuf, UINT nCount);
	DWORD Write(const void* lpBuf, UINT nCount);

	BOOL LockRange(ULONGLONG dwPos, ULONGLONG dwCount);
	BOOL UnlockRange(ULONGLONG dwPos, ULONGLONG dwCount);

	void Abort();
	void Flush();
	void Close();

// Implementation
public:
	virtual ~CFile();

	enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
	enum BufferFlags 
	{ 
		bufferDirect = 0x01,
		bufferBlocking = 0x02
	};


protected:
	BOOL m_bCloseOnDelete;
	CString m_strFileName;
};
